import { XFetch } from '@mpxjs/fetch'
import RequestSuccessCallbackResult = WechatMiniprogram.RequestSuccessCallbackResult;
import {baseUrl} from "./consts";
const request = new XFetch().create(); // 生成新的mpx-fetch实例

request.interceptors.request.use(config => {
  config.url = baseUrl + config.url;
  config.header = { // 一定要传
    'content-type': 'application/json'
  }
  return config;
});
request.interceptors.response.use((res: RequestSuccessCallbackResult) => {
  if (res.statusCode >= 200 && res.statusCode <= 300) {
    return res.data;
  }
  return Promise.reject(res);
});

export { request };
